//
//  TestViewController.m
//  JKOCTextView
//
//  Created by 王冲 on 2018/1/22.
//  Copyright © 2018年 希爱欧科技有限公司. All rights reserved.
//

#import "TestViewController.h"
#define CIO_SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define CIO_SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
#define TitleBlackCOLOR [UIColor colorWithRed:(51)/255.0 green:(51)/255.0 blue:(51)/255.0 alpha:1]
#define backGayCOLOR [UIColor colorWithRed:(232)/255.0 green:(232)/255.0 blue:(232)/255.0 alpha:1]
@interface TestViewController ()<UITextViewDelegate>

/**
    UITextView输入框的创建
 */
@property(nonatomic,strong) UITextView *jkTextView;
/**
    提示内容
 */
@property(nonatomic,strong) UILabel *placeholderLabel;
/**
    键盘上添加一个view
 */
@property(nonatomic,strong) UIView *jkInputAccessoryView;



@end

@implementation TestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:self.jkTextView];
    [self.jkTextView addSubview:self.placeholderLabel];
    self.jkTextView.inputAccessoryView = self.jkInputAccessoryView;
    
}

#pragma mark  textview的变化
-(void)textViewDidChange:(UITextView *)textView{
    
    self.placeholderLabel.hidden = textView.hasText;
}

-(UITextView *)jkTextView{
    
    if (!_jkTextView) {
        
        _jkTextView = [[UITextView alloc]initWithFrame:CGRectMake(0, 0, CIO_SCREEN_WIDTH,CIO_SCREEN_HEIGHT-64)];
        [_jkTextView becomeFirstResponder];
        // UITextView可以垂直滑动弹出键盘
        _jkTextView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
        _jkTextView.alwaysBounceVertical = YES;
        _jkTextView.delegate = self;
        _jkTextView.backgroundColor = [UIColor whiteColor];
        _jkTextView.textColor = TitleBlackCOLOR;
        _jkTextView.font = [UIFont systemFontOfSize:16.f];
    }
    
    return _jkTextView;
}

-(UILabel *)placeholderLabel{
    
    if (!_placeholderLabel) {
        
        _placeholderLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 9, CIO_SCREEN_WIDTH-10, 22)];
        _placeholderLabel.text = @"分享新鲜事";
        _placeholderLabel.textColor = backGayCOLOR;
        _placeholderLabel.font = [UIFont systemFontOfSize:20];
    }
    
    return _placeholderLabel;
}

-(UIView *)jkInputAccessoryView{
    
    if (!_jkInputAccessoryView) {
    
        _jkInputAccessoryView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CIO_SCREEN_WIDTH, 44)];
        _jkInputAccessoryView.backgroundColor = [UIColor redColor];
    }
    return _jkInputAccessoryView;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
